package com.baojee.index.service.impl;


import com.baojee.index.entity.PageItem;
import com.baojee.index.entity.ResponseResult;
import com.baojee.index.service.IndexService;
import com.kt.common.json.JsonUtils;
import com.kt.common.redis.template.ShardedJedisTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Auther: mg
 * @Date: 2021/06/22/18:15
 * @Description:
 */
@Service
public class IndexServiceImpl implements IndexService {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ShardedJedisTemplate shardedJedisTemplate;

    @Override
    public ResponseResult findAppIndexDataV6() {
       String str = this.shardedJedisTemplate.get("shop:application:index:v5");

        if (str == null) {
            return ResponseResult.success();
        }
        return ResponseResult.success();
    }

    @Override
    public List<PageItem> getIconList(String type){
        ArrayList<PageItem> list = new ArrayList<>();

            Map<String, String> stringStringMap = shardedJedisTemplate.hgetAll(type);
            List<String> strings = stringStringMap.values().stream().collect(Collectors.toList());
            logger.info("strings：{}",strings);
            strings.forEach(s  -> System.out.println(s));

            for (String value : stringStringMap.values()) {
                logger.info("value：{}",value);
                list.add(JsonUtils.json2Object(value, PageItem.class));
            }
            logger.info("list：{}",list);
            return list;

    }

}
